home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-06-03 | 5.7 KB | 242 lines | [TEXT/MPS ] |
- /******************************************************************************
- **
- ** Folder Name: BS
- ** File Name: INIT.c
- **
- ** Copyright: © 1993 Siren Enterprises, all rights reserved.
- **
- ** Description: Lil´ BeepSay - loads resident code, shows icons.
- **
- *******************************************************************************
- ** A U T H O R I D E N T I T Y
- *******************************************************************************
- **
- ** Initials Name
- ** -------- -----------------------------------------------
- ** kw Ken Wieschhoff
- ** DS Dave Spotts
- **
- *******************************************************************************
- ** R E V I S I O N H I S T O R Y
- *******************************************************************************
- **
- ** Date Time Author Description
- ** -------- ----- ------ ---------------------------------------------
- ** 05/17/93 15:30 KW Original version
- **
- ******************************************************************************/
-
- // Make sure the compiler only generates 68000 code. We'll catch missing
- // components below.
- #pragma processor 68000
-
- #include <OSUtils.h>
- #include <Files.h>
- #include <Types.h>
- #include <Resources.h>
- #include <PLStringFuncs.h>
- #include <Notification.h>
- #include <Packages.h>
- #include "ShowINIT.h"
- #include "Resident.h"
- #include "Preferences.h"
- #include "Utilities.h"
-
- //
- // System Traps enhanced.
- //
- #define cGestaltTrapNum 0xAD
- #define cHWPrivTrapNum 0xA198
- #define cUnImplTrapNum 0x9F
-
- // ResIDs of ICN# and cicn resources to indicate status
-
- #define cShowInitSucc 0
- #define cShowInitGesNotImp 1
- #define cShowInitFCBErr 2
- #define cShowResNotloaded 3
- #define cShowInitResNF 4
-
- TrapType GetTrapType(short theTrap);
-
- // ResidentMain function 'prototype'
- typedef pascal OSErr (*mainFuncPtr)(StringPtr fileName, short volume, long dirID);
-
-
-
- entrypoint()
- {
- Boolean GestaltIsImplemented;
- OSErr err;
- Handle ourHandle;
- FCBPBRec theParmBlock;
- Str255 theName;
- short theRefNum;
- short iconID = cShowInitSucc;
- long dummy;
- PreferencesHdl thePreferences = nil;
-
- // Don't load w/o Gestalt
- GestaltIsImplemented = (NGetTrapAddress(cGestaltTrapNum,GetTrapType( cGestaltTrapNum)) !=
- NGetTrapAddress(cUnImplTrapNum, GetTrapType( cUnImplTrapNum)));
- if (!(GestaltIsImplemented)) {
- iconID = cShowInitGesNotImp;
- goto exit;
- }
-
- // Get ahold of ourselves.
- ourHandle = RecoverHandle((Ptr) entrypoint);
-
- // turn it into a resRefNum
- theRefNum = HomeResFile(ourHandle);
-
- theParmBlock.ioRefNum = theRefNum;
- theParmBlock.ioFCBIndx = (long) 0;
- theParmBlock.ioNamePtr = &theName;
-
- // Find our file name, volume, and dirID
- err = PBGetFCBInfo(&theParmBlock, false);
- if ( err != noErr) {
- iconID = cShowInitFCBErr;
- goto exit;
- }
-
-
-
- // Checked all we can check, load/detach/call the resident code.
- {
- Handle residentCode;
- mainFuncPtr codeMain;
- THz saveZone;
-
-
- // Force the code to load in the system heap AND force the code's globals,
- // segments, etc. to go there too! It remembers the 'zone' it loads in
- // and makes it the current zone for all subsequent work it has to do.
- saveZone = GetZone();
- SetZone( SystemZone() );
-
- residentCode = Get1Resource( 'SYSB', 1);
- if ( residentCode == nil) {
- iconID = cShowInitResNF;
- SetZone( saveZone);
- goto exit;
- }
-
- MoveHHi( residentCode);
- HLock( residentCode); // Should be already, but doesn't hurt
- DetachResource( residentCode);
- codeMain = ( mainFuncPtr ) (*residentCode);
-
- // Call the main routine to set trap, add Gestalt, add Apple Event support, etc.
- err = (*codeMain)( &theName[0], theParmBlock.ioFCBVRefNum, theParmBlock.ioFCBParID);
-
- SetZone( saveZone);
-
-
- }
-
- if ( err ) {
- iconID = cShowResNotloaded;
- goto exit;
- }
-
- // Read the preferences from disk
- err = _ReadPreferences( &thePreferences, kBeepSayPrefs);
- if (( err ) || !(**thePreferences).iconAtStartup)
- iconID = -1;
-
-
- exit:
-
- if ( thePreferences != nil)
- DisposeHandle( (Handle) thePreferences);
-
- if ( iconID >= 0) {
- ShowINIT( iconID, -1);
- Delay( 60L, &dummy); // Wait a second…
- }
-
- }
-
-
- TrapType GetTrapType(short theTrap)
-
- {
- // OS traps start with A0, Tool with A8 or AA.
- if ((theTrap & 0x0800) == 0) // per D.A.
- return OSTrap;
- else
- return ToolTrap;
- } // GetTrapType
-
- pascal void _DisposeError( NMRec *theNMRec)
- {
- OSErr err;
-
- err = NMRemove( theNMRec);
-
- DisposePtr( (Ptr) theNMRec->nmStr );
- DisposePtr( (Ptr) theNMRec );
- }
-
- pascal void DisposeError( NMRec *theNMRec)
- {
- long hostA5;
- Handle ourA5 = *OldSysBeep();
-
- hostA5 = GetA5();
-
-
- SetA5((long)StripAddress((*ourA5)) + A5Size() - 32);
-
- _DisposeError( theNMRec);
-
- RestoreA5World( hostA5);
- }
-
- pascal void ShowStr( StringPtr str)
- {
- NMRec* nmPtr;
- StringPtr text;
-
- // Use the Notification Manager to report errors.
- nmPtr = (NMRec*) NewPtr( sizeof( NMRec) );
- if ( nmPtr == nil) {
- return;
- }
- text = (StringPtr) NewPtr( str[0] + 1);
- if ( text == nil) {
- DisposePtr( (Ptr) nmPtr);
- return;
- }
- PLstrcpy( text, str);
-
- nmPtr->qType = 8;
- nmPtr->nmMark = 0; // no mark in application menu
- nmPtr->nmIcon = nil; // nil = no icon in menubar or a handle to SICN resource
- nmPtr->nmSound = (Handle)-1; // pick a sound, use -1 for System Beep or nil for no sound.
- nmPtr->nmStr = text; // display this string in dialog
- nmPtr->nmResp = (NMProcPtr)DisposeError; // Routine to dispose of the pointer block. (nil - Use default)
- nmPtr->nmRefCon = 0L; // no refcon
-
- if( NMInstall( nmPtr) != noErr) {
- DisposePtr( (Ptr) nmPtr);
- DisposePtr( (Ptr) text);
- }
- }
-
-
- pascal void ShowStrNum( StringPtr str, OSErr err)
- {
- Str255 errText, strText;
-
- NumToString( (long) err, errText);
-
- PLstrcpy(strText, str);
- PLstrcat(strText,"\p Error = ");
- PLstrcat(strText, errText);
- ShowStr( strText);
- }
-
-